﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ZDSoft.UPMS.Model.SystemPart;
using ZDSoft.UPMS.Service.SystemPart;
using Castle.ActiveRecord;

namespace ZDSoft.UPMS.Manager.SystemPart
{
    public class RoleManager : ManagerBase<Role>
    {
       //3456790
        public new void Create(Role role)
        {

            string[] ids = role.systemfunctionId.Split(',');


            role.SystemFunctions = new List<SystemFunction>();
            foreach (string id in ids)
            {
                if (id == "" || id == "undefined")
                {
                    continue;
                }
                SystemFunction modle = ZDSoft.UPMS.Core.Container.Instance.Resolve<ISystemFunctionService>().FindByID(int.Parse(id));
                role.SystemFunctions.Add(modle);
            }
            ActiveRecordBase.Create(role);
        }
        public new void Update(Role roles)
        {
            roles.SystemFunctions = null;
            string[] ids = roles.systemfunctionId.Split(',');
            roles.SystemFunctions = new List<SystemFunction>();
            foreach (string id in ids)
            {
                if (id == "" || id == "undefined")
                {
                    continue;
                }
                SystemFunction modle = ZDSoft.UPMS.Core.Container.Instance.Resolve<ISystemFunctionService>().FindByID(int.Parse(id));

                roles.SystemFunctions.Add(modle);
            }
            ActiveRecordBase.Update(roles);
        }
    }
}
